<?php
/**
 * Well Framework
 * 
 * Session Class
 *
 * It combaines all user session data to one storage
 * For this time it include only $_SESSION glob var.
 * 
 * @package     Well
 * 
 * @author valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright fremar ltd.
 */
class Session
{            
    /**
     * Session start
     */
    public function __construct()
    {
        session_start();
    }
          
    /**
     * Get element from session data storage
     * 
     * @param string $key
     * @return $_SESSION[$key] 
     */
    public function get( $key )
    {
        if ( !is_array($key) ){
            
            $val    =   isset($_SESSION[$key])                    ?  $_SESSION[$key]   :   null;                 
        } else {            
            $val    =   isset( $_SESSION[$key[0]] [$key[1]] )     ?  $_SESSION[$key[0]] [$key[1]]   :   null;
        }
        return $val;
    }
    
    /**
     * Put element to session data storage
     * 
     * @param string $key
     * @param mixed $val 
     */
    public function set($key, $val)
    {
        if (!is_array($key)){                        
            
            $_SESSION[ (string)$key ]     =   $val;                                               
            
        } elseif ( count($key) == 2 ) {   
            
            $_SESSION[ (string)$key[0] ] [ (string)$key[1] ]  =   $val;     }
    }
    
    /**
     * Set element with name complex to session storage
     * @param Complex $complex 
     */
    public function setComplex(Complex $complex)
    {
        $this-> set('complex',$complex);
    }
    
    /**
     * Return Complex element from session storage
     * @return Complex $complex 
     */
    public function getComplex()
    {
        return $this-> get('complex');
    }
    
    /**
     * Remove value from session
     * 
     * @param string $key
     * @return bool |   true
     */
    public function erase($key)
    {
        if ( isset ($_SESSION[(string)$key]) )
             unset ($_SESSION[(string)$key]);
        
        return true;
    }
}
?>
